<?php
/**
* smarty function to get constant value which define before
* @param  name    the constant name
* @param  assign  the assign to variable name
* @return string of value or assign to value if assign param is set
*/
function smarty_function_topic_validate($params, &$smarty) 
{
    $topic_id = $params['topic_id'];

    if($topic_id){
      //Query data
      $pntables = pnDBGetTables();
      $table  = $pntables['innoforum_topics'];
      $column = $pntables['innoforum_topics_column'];

      $sql = "SELECT
                $table.$column[id]
              FROM
                $table
              WHERE
                $table.$column[id] = ".$topic_id;
      $column = array("tpc_id");
      $result = DBUtil::executeSQL($sql);
      $objectArray = DBUtil::marshallObjects ($result, $column);

      if(sizeof($objectArray) > 0){
        $smarty->assign('topic_validate', '1'); 
      }else{
        $smarty->assign('topic_validate', '0'); 
      }
    } else {
        $smarty->assign('topic_validate', '0'); 
    }
}